package com.ui.basic.service.report;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ui.basic.ibatis.dao.admin.TblAExchangeRateDAO;
import com.ui.basic.ibatis.dao.log.TblLogExchangeRateDAO;
import com.ui.basic.ibatis.model.admin.TblAExchangeRate;
import com.ui.basic.ibatis.model.log.TblLogExchangeRate;

@Service("logExchangeRateService")
public class LogExchangeRateServiceImpl implements LogExchangeRateService {
	private static final transient org.apache.commons.logging.Log LOGGER = org.apache.commons.logging.LogFactory.getLog(LogExchangeRateServiceImpl.class);
	
	@Autowired
	private TblLogExchangeRateDAO tblLogExchangeRateDAO;
	@Autowired
	private TblAExchangeRateDAO tblAExchangeRateDAO;
	
	public void setTblLogExchangeRateDAO(TblLogExchangeRateDAO tblLogExchangeRateDAO) {
		this.tblLogExchangeRateDAO = tblLogExchangeRateDAO;
	}

	public void setTblAExchangeRateDAO(TblAExchangeRateDAO tblAExchangeRateDAO) {
		this.tblAExchangeRateDAO = tblAExchangeRateDAO;
	}

	public void logUpdateRate(TblAExchangeRate tblAExchangeRate)
			throws SQLException {
		LOGGER.debug(">>>LogExchangeRateServiceImpl.logUpdateRate");
		
		TblAExchangeRate exchangeRate = tblAExchangeRateDAO.selectByPrimaryKey(tblAExchangeRate.getId());
		
		tblAExchangeRateDAO.updateByPrimaryKeySelective(tblAExchangeRate);
		
		TblLogExchangeRate logExchangeRate = new TblLogExchangeRate();
		logExchangeRate.setSrcCurrId(tblAExchangeRate.getSrcCurrId());
		logExchangeRate.setDestCurrId(tblAExchangeRate.getDestCurrId());
		logExchangeRate.setRate(exchangeRate.getRate());
		logExchangeRate.setCommission(exchangeRate.getCommission());
		logExchangeRate.setActiveDate(exchangeRate.getCreateddate());
		logExchangeRate.setExpiredDate(tblAExchangeRate.getCreateddate());
		logExchangeRate.setCreatedby(exchangeRate.getCreatedby());
		logExchangeRate.setCreateddate(exchangeRate.getCreateddate());
		
		tblLogExchangeRateDAO.insert(logExchangeRate);
	}
	
	
}
